/**
 * @program: 程序设计理论与方法_202130504106_李航
 * @description: Mike, Ellie, Rohan, Fatma四个人参加自行车比赛，分别获得1-4名，
 * 他们每个人骑不同颜色的自行车（红，紫，蓝，绿）。基于以下线索，谁获得了第二名？
 * Ellie骑紫色的车，Rohan没有骑绿色的车。
 * Mike和Ellie不是第一，也不是最后。
 * 骑蓝色车的人领先Fatma。
 * 骑绿色车的人领先骑紫色车的人。
 * @author: LiHang
 * @create: 2021-09-13 16:42
 **/

public class Bike {

    public static void main(String[] args) {
        Bike bike = new Bike();

        //暴力破解
        String baoliResult=bike.baoli();
        System.out.println(baoliResult);
    }

    /**
     * 暴力破解法，无限for循环
     * 思路就人名和排名，车辆颜色和排名做个配对
     *
     * @return 第二名的名字
     */
    public String baoli() {
        int Mike = 0, Ellie = 0, Rohan = 0, Fatma = 0;
        int red = 0, purple = 0, blue = 0, green = 0;
        String result="";
        for (Mike = 1; Mike < 5; Mike++) {
            for (Ellie = 1; Ellie < 5; Ellie++) {
                for (Rohan = 1; Rohan < 5; Rohan++) {
                    for (Fatma = 1; Fatma < 5; Fatma++) {
                        for (red = 1; red < 5; red++) {
                            for (purple = 1; purple < 5; purple++) {
                                for (blue = 1; blue < 5; blue++) {
                                    for (green = 1; green < 5; green++) {
                                        if (Mike != Ellie && Mike != Rohan && Mike != Fatma && Ellie != Rohan && Ellie != Fatma && Rohan != Fatma) {
                                            if(red != purple && red != blue && red != green && purple != blue && purple != green && blue != green){
                                                if (Ellie == purple && Rohan != green) {
                                                    if (Mike != Ellie && Mike != 1 && Mike != 4 && Ellie != 1 && Ellie != 4) {
                                                        if (blue < Fatma) {
                                                            if (green < purple) {
                                                                System.out.println("排名  MIke："+Mike + " Ellie:" + Ellie + " Rohan:" + Rohan + " Fatma:" + Fatma);
                                                                //System.out.println("车辆颜色"+red + " " + purple + " " + blue + " " + green);

                                                                if(Mike==2){
                                                                    result+="Mike骑着";
                                                                }else if(Ellie==2){
                                                                    result+="Ellie骑着";
                                                                }else if(Rohan==2){
                                                                    result+="Rohan骑着";
                                                                }else{
                                                                    result+="Fatma骑着";
                                                                }

                                                                if(red==2){
                                                                    result+="red(红色自行车)获得了第二";
                                                                }else if(purple==2){
                                                                    result+="purple(紫色自行车)获得了第二";
                                                                }else if(blue==2){
                                                                    result+="blue(蓝色自行车)获得了第二";
                                                                }else{
                                                                    result+="green(绿色自行车)获得了第二";
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return result;
    }

}
